import BaseSprite from "../../Base/BaseSprite";
import EventID from "../../Common/EventID";
import { IMessage } from "../../Interface/IMessage";

const { ccclass, property } = cc._decorator;

@ccclass
export class ItemBlock extends BaseSprite implements IMessage {

    @property({ type: dragonBones.ArmatureDisplay, tooltip: "龙骨动画" })
    private block_ske: dragonBones.ArmatureDisplay = null;

    @property({ type: cc.Label, tooltip: "索引" })
    private label: cc.Label = null;

    private data = null;

    recvMsg(cmd: number, data: any): void {
        switch (cmd) {
            case EventID.TEST_CMD:

                break;
        }
    }

    protected onLoad() {
        this.addMessage(EventID.TEST_CMD, this);
    }

    protected start() { }

    protected onEnable() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    protected onDisable() {
        this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
        this.node.off(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.node.off(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    public setData(data) {
        this.data = data;
        this.label.string = `${data.index}`;
    }

    private onTouchStart(event: cc.Event.EventTouch) {
        const stageX = event.getLocation().x;
        const stageY = event.getLocation().y;
    }

    private onTouchMove() { }
    private onTouchEnd() {}
    private onTouchCancel() { }
}